/*
 *    Copyright (c) 2018-2025, daoism All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: daoism
 */

package com.mkh.st.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mkh.st.admin.api.dto.*;
import com.mkh.st.admin.api.entity.*;
import com.mkh.st.admin.api.vo.*;
import com.mkh.st.admin.service.*;
import com.mkh.st.common.core.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;


/**
 * 地区
 *
 * @author daoism code generator
 * @date 2021-07-06 09:16:57
 */
@RestController
@AllArgsConstructor
@RequestMapping("/system" )
@Api(value = "system", tags = "系统资源管理")
public class SystemController {

    private final  SysAreaService sysAreaService;

    private final SysImageConfigService sysImageConfigService;

	private final SysDocTypeService sysDocTypeService;

	private final SysCountryService sysCountryService;

	private final StSnService stSnService;

	private final SysBusinessSetService businessSetService;

	private final StFinancialSetService financialSetSave;

//-------------------地区表表----------------------------------
    /**
     * 通过id查询地区
	 *
	 * 省份parentId=0;
     * @param parentId parentId
     * @return R
     */
    @ApiOperation(value = "省市列表查询", notes = "省市列表查询")
    @GetMapping("/arealist" )
    public R<List<SysArea>> getListByParentId(@RequestParam Long parentId) {
        return sysAreaService.getListByParentId(parentId);
    }
	@ApiOperation(value = "省市查询", notes = "省市查询")
	@GetMapping("/getArea" )
	public R<SysArea> getArea(@RequestParam Long areaCode) {
		return R.ok(sysAreaService.getOne(Wrappers.<SysArea>lambdaQuery().eq(SysArea::getAreaCode,areaCode)));
	}

	@ApiOperation(value = "地区列表查询", notes = "地区列表查询")
	@GetMapping("/getCountrylist" )
	public R<List<SysCountry>> getCountrylist() {
		return R.ok(sysCountryService.list(Wrappers.<SysCountry>lambdaQuery().orderByDesc(SysCountry::getId)));
	}

	@ApiOperation(value = "根据id查询地区信息", notes = "根据id查询地区信息")
	@GetMapping("/getCountryInfo" )
	public R<SysCountry> getCountryInfo(@RequestParam Long countryId ) {
		return R.ok(sysCountryService.getById(countryId));
	}

//-------------------图片配置表----------------------------------
	@ApiOperation(value = "图片配置查询", notes = "图片配置查询")
	@GetMapping("/getImageCongif" )
	public R<SysImageConfig> getImageCongif() {
		return sysImageConfigService.getImageCongif();
	}

	@ApiOperation(value = "图片配置保存", notes = "图片配置保存")
	@PostMapping("/saveImageCongif")
	public R<Boolean> saveImageCongif(@Valid @RequestBody SysImageConfigSaveDTO dto) {
		return sysImageConfigService.saveImageCongif(dto);
	}

//-------------------单据类型表----------------------------------
	@ApiOperation(value = "单据类型查询", notes = "单据类型查询")
	@GetMapping("/docTypePage" )
	public R<IPage<DocTypePageVO>> docTypePage(Page page, DocTypePageDTO dto) {
		return sysDocTypeService.docTypePage(page,dto);
	}

	//-------------------单据编码表----------------------------------
	@ApiOperation(value = "单据编码查询", notes = "单据编码查询")
	@GetMapping("/snPage" )
	public R<IPage<SnPageVO>> snPage(Page page, @RequestParam(required = false) Long id) {
		return R.ok(stSnService.snPage(page,id)) ;
	}

	@ApiOperation(value = "单据类型集合查询", notes = "单据类型集合查询")
	@GetMapping("/snList")
	public R<List<SnListVO>> snList() {
		return R.ok(stSnService.snList()) ;
	}

	@ApiOperation(value = "单据编码保存", notes = "单据编码保存")
	@PostMapping("/saveSn" )
	public R<Boolean> saveSn(@Valid @RequestBody StSnSaveDTO dto) {
		return stSnService.saveSn(dto);
	}

	//-------------------业务配置----------------------------------
	@ApiOperation(value = "业务配置保存", notes = "业务配置保存")
	@PostMapping("/businessSetSave" )
	public R<Boolean> busnessSetSave(@Valid @RequestBody SysBusinessSetDTO dto) {
		return R.ok(businessSetService.businessSetSave(dto));
	}

	@ApiOperation(value = "业务配置查询", notes = "业务配置查询")
	@GetMapping("/getBusnessSet")
	public R<SysBusinessSetVO> getBusnessSet(@ApiParam(name = "siteId", value = "业务线id",required = true) Long siteId) {
		return R.ok(businessSetService.getBusnessSet(siteId)) ;
	}

	//-------------------财务配置----------------------------------

	@ApiOperation(value = "财务配置保存", notes = "财务配置保存")
	@PostMapping("/financialSetSave" )
	public R<Boolean> financialSetSave(@Valid @RequestBody StFinancialSetDTO dto) {
		return R.ok(financialSetSave.financialSetSave(dto));
	}

	@ApiOperation(value = "财务配置查询", notes = "财务配置查询")
	@GetMapping("/getFinancialSet")
	public R<StFinancialSet> getFinancialSet() {
		return R.ok(financialSetSave.getFinancialSet()) ;
	}
}
